import 'package:flutter/material.dart';
import 'package:xinxuan/common/appbar_util.dart';
import 'package:xinxuan/common/network_image_util.dart';
import 'package:xinxuan/controllers/cooperation_controller/subsidy_page_controller.dart';
import 'package:xinxuan/utils/color_util.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:xinxuan/utils/refresh_util.dart';
import 'package:xinxuan/vo/activity_subsidies_vo.dart';

class SubsidyPage extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: pageBgColor,
      appBar: AppBarUtil(
        title: '补贴金发放',
        backgroundColor: bgWhiteColor,
      ),
      body: GetBuilder<SubsidyPageController>(
        init: SubsidyPageController(),
        builder: (controller) {
          return Column(
            children: [
              Container(
                height: 54.h,
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.symmetric(horizontal: 16.w),
                child: Text(
                  '合计获得补贴金共 ${controller.activitySubsidiesVo.value.meta!.totalSubsidy} 元',
                  style: TextStyle(
                    color: textBlackColor,
                    fontSize: 16.sp
                  ),
                ),
              ),
              Expanded(child: RefreshUtil.easyRefresh(
                onRefresh: () async {
                  controller.getActivitySubsidies();
                },
                onLoad: () async {
                  controller.onLoadActivitySubsidies();
                },
                slivers: [
                  SliverList(
                    delegate: SliverChildBuilderDelegate((context, index) {
                      ActivitySubsidiesItem item = controller.activitySubsidiesVo.value.data![index];
                      return Container(
                        padding: EdgeInsets.symmetric(horizontal: 12.w),
                        color: bgWhiteColor,
                        child: Container(
                          padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 16.h),
                          decoration: BoxDecoration(
                            border: Border(
                              bottom: BorderSide(
                                color: lineColor,
                                width: .5
                              )
                            )
                          ),
                          child: Row(
                            children: [
                              NetworkImageUtil(
                                url: '',
                                nickname: '${item.username}', 
                                width: 36.w, 
                                height: 36.w,
                                showShadow: false,
                              ),
                              SizedBox(width: 12.w),
                              Expanded(child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Text(
                                    '${item.username}',
                                    style: TextStyle(
                                      color: textBlackColor,
                                      fontSize: 16.sp,
                                      fontWeight: FontWeight.bold
                                    ),
                                  ),
                                  Text(
                                    '${item.createdAt}',
                                    style: TextStyle(
                                      color: textSubtitleColor,
                                      fontSize: 12.sp
                                    ),
                                  )
                                ],
                              )),
                              Text(
                                '${item.subsidy}',
                                style: TextStyle(
                                  color: textSuccessColor,
                                  fontSize: 16.sp
                                ),
                              )
                            ],
                          ),
                        ),
                      );
                    }, childCount: controller.activitySubsidiesVo.value.data!.length),
                  )
                ]
              ))
            ],
          );
        },
      ),
    );
  }
}